import { getOrderListReq } from '../request/order'
const actions = {
  // 获取订单列表
  async getOrderList(context, params) {
    try {
      const orderListData = await getOrderListReq(params)
      orderListData.goods.forEach(
        g => (g.time = new Date(g.create_time).toLocaleString())
      )

      context.commit('GET_ORDER_LIST', orderListData)
    } catch (error) {
      return Promise.reject(error)
    }
  },
}
const mutations = {
  GET_ORDER_LIST(state, orderListData) {
    state.orderListData = orderListData
  },
}
const state = {
  orderListData: {}, // 订单列表对象
}

const getters = {
  orderList(state) {
    return state.orderListData.goods
  },
}

export default {
  namespaced: true,
  actions,
  mutations,
  state,
  getters,
}
